package com.wwt.blog.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wwt.blog.pojo.Article;
import com.wwt.blog.pojo.dos;
import com.wwt.blog.vo.param.PageParams;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ArticleMapper extends BaseMapper<Article> {

    //最热文章 即浏览量最高的 取4篇
    @Select("select id,comment_counts,title from ms_article order by comment_counts desc limit 4")
    List<Article> getHotArticles();
    //最新文章 取5篇
    @Select("select id,title from ms_article order by create_date desc limit #{limit}")
    List<Article> getNewArticles(int limit);

    //文章归档的实现
    @Select("select year(FROM_UNIXTIME(create_date/1000)) as year,\n" +
            "       month(FROM_UNIXTIME(create_date/1000)) as month, count(*) as count from ms_article\n" +
            "group by year,month")
    List<dos> getListArchives();

    //重写
    IPage<Article> listArticles(Page<Article> page, Long tagId,Long categoryId,
                                String year,String month);
}
